﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Bovril.PlayingCards.French;

namespace Bovril.Poker
{
    internal struct CardComparer : IComparer<Card>
    {
        internal CardComparer(int majorRank)
        {
            hasMajorRank_ = true;
            majorRank_ = majorRank;
            hasMinorRank_ = false;
            minorRank_ = RankValue.Two;
        }

        internal CardComparer(int majorRank, int minorRank)
        {
            hasMajorRank_ = true;
            majorRank_ = majorRank;
            hasMinorRank_ = true;
            minorRank_ = minorRank;
        }

        public int Compare(Card x, Card y)
        {
            int xRankValue = x.Rank;
            int yRankValue = y.Rank;

            if (hasMajorRank_)
            {
                if (x.Rank == majorRank_)
                    xRankValue = 100;
                if (y.Rank == majorRank_)
                    yRankValue = 100;
            }

            if (hasMinorRank_)
            {
                if (x.Rank == minorRank_)
                    xRankValue = 50;
                if (y.Rank == minorRank_)
                    yRankValue = 50;
            }

            if (xRankValue != yRankValue)
                return yRankValue - xRankValue;
            else
                return x.Suit - y.Suit;
        }

        private bool hasMajorRank_;
        private bool hasMinorRank_;
        private int majorRank_;
        private int minorRank_;
    }
}
